const path = require('path');
const Application = require('thinkjs');

const instance = new Application({
  //在启动文件中可以自定义配置 runtime 目录
  RUNTIME_PATH: path.join(process.cwd(), 'runtime'), 
  ROOT_PATH: __dirname,
  proxy: true,
  env: 'pkg',
  
});

instance.run();

function conf(vax, fa) {
  for (var key in vax) {
      if (typeof vax[key] === 'object') {
          if (fa !== undefined) {
              conf(vax[key], fa + "." + key)
          } else {
              conf(vax[key], key)
          }
      } else {
          if (fa !== undefined) {
            think.config( fa + '.' + key, vax[key]);
          } else {
            think.config(key, vax[key]);
          }
          
      }
  }
}

think.beforeStartServer(() => {
  const configFile = path.join(process.cwd(), 'config.js');
  const config = require(configFile);
    conf(config)
});